import base64
from openai import OpenAI

def encode_image(image_path):
    with open(image_path, "rb") as image_file:
        return base64.b64encode(image_file.read()).decode('utf-8')

# 初始化 OpenAI 客户端
client = OpenAI(
    base_url="http://localhost:8000/v1",
    api_key="test"
)

# 本地图片路径
image_path = "./1.jpeg"

# 编码图片
base64_image = encode_image(image_path)

response = client.chat.completions.create(
        model="./qwen2.5_vl_7B",
        messages=[
            {
                "role": "user",
                "content": [
                    {"type": "text", "text": "描述图片内容，使用中文。"},
                    {
                        "type": "image_url",
                        "image_url": {
                            "url": f"data:image/jpeg;base64,{base64_image}",
                            },
                        },
                    ],
                }
            ],
        max_tokens=1024,
        )

print(response.choices[0])
